package com.hzit.loan.pay.service.impl;

import com.hzit.loan.pay.commonApi.req.RefundReq;
import com.hzit.loan.pay.commonApi.resp.RespVo;
import com.hzit.loan.pay.commonApi.utils.IdWorker;
import com.hzit.loan.pay.mapper.RefundSerialMapper;
import com.hzit.loan.pay.model.PaySerial;
import com.hzit.loan.pay.model.RefundSerial;
import com.hzit.loan.pay.service.IRefundSerialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class RefundSerialServiceImpl implements IRefundSerialService {

    @Autowired
    private RefundSerialMapper refundSerialMapper;

    @Override
    public List<RefundSerial> queryByPaySerialNo(String paySerialNo) {

        List<RefundSerial>  refundSerialList = refundSerialMapper.selectBySerialNo(paySerialNo);

        return refundSerialList;
    }

    @Override
    public RefundSerial createRefundSerial(RefundReq refundReq, PaySerial paySerial) {

        RefundSerial refundSerial = new RefundSerial();
        Date nowDate = new Date();
        IdWorker worker = new IdWorker(1,1,1);
        refundSerial.setRefundSerialNo(String.valueOf(worker.nextId()));
        refundSerial.setApplyTime(nowDate);
        refundSerial.setOriPaySerialNo(refundReq.getPaySerialNo());
        refundSerial.setRefundStatus("1"); //状态
        refundSerial.setRefundReason(refundReq.getRefundReason());
        refundSerial.setRefundAmount(new BigDecimal(refundReq.getRefundAmt()));
        refundSerial.setPayChannel(paySerial.getPayChannel());

        refundSerialMapper.insertSelective(refundSerial);

        return refundSerial;
    }

    /**
     * 更新退款的流水
     */
    @Override
    public void updateRefundSerial() {

        refundSerialMapper.updateByPrimaryKey(null);

    }
}
